import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "/querylike",urlPatterns = "/querylike")
public class QueryLike extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //获得请求参数
        String sno = req.getParameter("sno");
        String name = req.getParameter("name");
        String grade = req.getParameter("grade");
        //设置编码方法
        resp.setContentType("text/html;charset=utf-8");
        List<Student> query = StudentDAO.queryLike(sno,name,grade);
        ObjectMapper mapper = new ObjectMapper();
        String s = mapper.writeValueAsString(query);
        resp.getWriter().write(s);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
